function [newpath] = update_paths(basepath, file)
% update_paths  -  search for a file starting in basepath
% the algorithm is as follows:
% look in the base path for the file.
% if it is found return newpath = basepath.
% look for a directory named nnmmmyy (datac form)
% if it is found, look for the file in that subdirectory.
% if not found, return an empty new path.
%   (eventually, we should do an iterative search of all paths under the base
%    path for the file...)
%

newpath = [];
if(nargin ~= 2)
   fprintf(2, 'update_paths: requires 2 arguments\n');
   return;
end;
if(exist(basepath,'dir') ~= 7)
 %  fprintf(2, 'update_paths: the base %s path is not an existing directory\n', basepath);
   return;
end;
basepath = append_backslash(basepath);

testfile = [basepath file];

if(exist(testfile, 'file') == 2)
   newpath = basepath;
   if(nargout == 0)
      fprintf(2, 'update_paths: file found in path %s\n', newpath);
      dir([newpath file])
   end;
   return;
end;

% file not found in target directory
% see if there is a subdirectory of the right name

if(length(file) < 11)
   fprintf(2, 'update_paths: filename is not datac style?\n');
   return;
end;

subdir = file(1:7);
testpath =append_backslash([basepath subdir]);
if(exist(testpath, 'dir') ~= 7)
 %  fprintf(2, 'update_paths: possible subdirectory %s not found\n', testpath);
   return;
end;

testfile = slash4OS([testpath file]);
if(exist(testfile, 'file') == 2)
   newpath = testpath;
   if(nargout == 0)
   %   fprintf(2, 'update_paths: file found in path %s\n', newpath);
      dir([newpath file])
   end;
   return;
else
 %  fprintf(2, 'update_paths: file %s not found in subdirectory %s\n', file, testpath');
   return;
end;


